<template>
  <div>
    <div style="height:420px;width: 1440px;">
      <Sankey
        ref="chart"/>
    </div>
    <div class="sum-num">总排放量：{{ sumNum }}</div>
    <div class="slider-body" v-for="(item, index) in siderList" :key="index">
      <div class="name">{{ item.name }}</div>
      <el-slider
        class="slider"
        v-model="item.num"
        @input="dragSlider(item)"
        :min="item.minNum"
        :max="item.maxNum"></el-slider>
      <div class="num-show"> {{ item.num }}</div>


    </div>

  </div>
</template>

<script>
import Sankey from "@/components/Chart/Sankey"

export default {
  components: {
    Sankey
  },
  mounted() {
    this.initSiderList()
  },
  data() {
    return {
      sumNum: 14352,
      siderList: [],
      ridList: [
        "直接排放",
        "能源间接排放",
        "运输间接排放",
        "其他间接排放"
      ]
    }
  },
  methods: {
    // 初始化可编辑数值
    initSiderList() {
      var maxList = this.$refs.chart.getMaxList()
      for (var i = 0; i < maxList.length; i++) {
        if (this.ridList.indexOf(maxList[i].name) == -1) {
          this.siderList.push({
            name: maxList[i].name,
            baseNum: maxList[i].value,
            maxNum: maxList[i].value * 1.5,
            minNum: 0,
            num: maxList[i].value,
          })
        }

      }
    },
    // 监听拖拽事件
    dragSlider(item) {
      var zoomRatio = item.num / item.baseNum
      this.$refs.chart.setDataAndRender(item.name, zoomRatio)
      this.sumNum = this.$refs.chart.getSumNum() * 5 + 352
    },
  }
}
</script>

<style>
.slider-body {
  display: flex;
  width: 100%;
  margin-left: 40px;
}

.slider {
  width: 1000px;

}

.name {
  line-height: 38px;
  margin-right: 10px;
  font-size: 18px;
  width: 100px;
}

.sum-num {
  position: fixed;
  font-size: 18px;
  top: 100px;
  left: 240px;
  font-weight: bolder;
}

.num-show {
  margin: auto;
  font-size: 16px;
  margin-left: 0px;
}
</style>
